package Commandes;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import projetjava.ApercuPhotoGrand;


public class Commande_Pivoter implements Commande{
    
 private double angle;
 private ApercuPhotoGrand apg;
     
    public Commande_Pivoter(ApercuPhotoGrand apg,double angle) {
        
        this.apg=apg;
        this.angle=angle;
    }
    
    public boolean executer() {
        
        this.rotation(angle);
        
        return true;
    }
    
    public boolean cancel() {

        this.rotation(-angle);
            

           return true;
    }
    
    public void rotation(double angle){
        BufferedImage image = apg.getApercu();
        int w = image.getWidth();
        int h = image.getHeight();
        BufferedImage dimg = dimg = new BufferedImage(w, h,BufferedImage.TYPE_INT_ARGB);
        AffineTransform at = new AffineTransform();
        at.rotate(Math.toRadians(angle),w/2,h/2);
        AffineTransformOp atop = new AffineTransformOp(at,AffineTransformOp.TYPE_BICUBIC);
        atop.filter(image,dimg);
        apg.setApercu(dimg);
    }
    
}
